package cn.id68.www.http.builder;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import cn.id68.www.http.RequestCall;

/**
 * Created by Administrator on 2017/3/21.
 */

public class PostFormBuilder extends OkHttpRequestBuilder<PostFormBuilder> {

    private List<FileInput> fileInputs = new ArrayList<>();


    @Override
    public RequestCall build() {
        return new PostFormBuilder().build();
    }

    public PostFormBuilder files(String key, Map<String,File> files){
        for (String filename:files.keySet()){
            this.fileInputs.add(new FileInput(key,filename,files.get("filename")));
        }
        return this;
    }

    public PostFormBuilder addFiles(String key,String filename,File file){
        fileInputs.add(new FileInput(key,filename,file));
        return this;
    }

    public static class FileInput{
        public String key;
        public String filename;
        public File file;

        public FileInput(String key, String filename, File file) {
            this.key = key;
            this.filename = filename;
            this.file = file;
        }

        @Override
        public String toString() {
            return "FileInput{" +
                    "key='" + key + '\'' +
                    ", filename='" + filename + '\'' +
                    ", file=" + file +
                    '}';
        }
    }
}
